﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace WHC.Hotel.Entity
{   
    /// <summary>
    /// 房源按类汇总
    /// </summary>
    public class RoomSumList
    {

        private static Dictionary<string, RoomUseInfo> roomTypeSumDic = new Dictionary<string, RoomUseInfo>();
        private static Dictionary<string, RoomUseInfo> roomBuildSumDic = new Dictionary<string, RoomUseInfo>();
        private static Dictionary<string, RoomUseInfo> roomFloorSumDic = new Dictionary<string, RoomUseInfo>();
      
        

        public  static void AddRoomTypeItem(string key,int inUse,int canUse,string  expand)
        {

            if (roomTypeSumDic.ContainsKey(key))
            {

                roomTypeSumDic[key].InUse = roomTypeSumDic[key].InUse + inUse;
                roomTypeSumDic[key].CanUse = roomTypeSumDic[key].CanUse + canUse;
                roomTypeSumDic[key].Expand = expand;
                roomTypeSumDic[key].RoomSum++;

            }
            else
            {
              
              roomTypeSumDic.Add(key ,new RoomUseInfo(key,inUse,canUse));
              roomTypeSumDic[key].RoomSum++;
            
            
            }
        
        
        }

        public static void AddRoomBuildItem(string key, int inUse, int canUse)
        {

            if (roomBuildSumDic.ContainsKey(key))
            {

                roomBuildSumDic[key].InUse = roomBuildSumDic[key].InUse + inUse;
                roomBuildSumDic[key].CanUse = roomBuildSumDic[key].CanUse + canUse;
                roomBuildSumDic[key].RoomSum++;

            }
            else
            {
                roomBuildSumDic.Add(key, new RoomUseInfo(key, inUse, canUse));
                roomBuildSumDic[key].RoomSum++;


            }


        }

        public static void AddRoomFloorItem(string key, int inUse, int canUse)
        {

            if (roomFloorSumDic.ContainsKey(key))
            {

                roomFloorSumDic[key].InUse = roomFloorSumDic[key].InUse + inUse;
                roomFloorSumDic[key].CanUse = roomFloorSumDic[key].CanUse + canUse;
                roomFloorSumDic[key].RoomSum++;

            }
            else
            {
                roomFloorSumDic.Add(key, new RoomUseInfo(key, inUse, canUse));
                roomFloorSumDic[key].RoomSum++;


            }

            


        }

        public static  List<RoomUseInfo>  RoomTypeSumList
        {

            get {

                List<RoomUseInfo> list = new List<RoomUseInfo>();
                foreach (RoomUseInfo item in roomTypeSumDic.Values)
                {
                   
                    list.Add(item);
                
                }

                return list;
            
            }
        
        
        }

        public static List<RoomUseInfo> RoomBuildSumList
        {

            get
            {

                List<RoomUseInfo> list = new List<RoomUseInfo>();
                foreach (RoomUseInfo item in roomBuildSumDic.Values)
                {

                    list.Add(item);

                }

                return list;

            }


        }

        private static int CompareByKey(RoomUseInfo roomUseInfoA, RoomUseInfo roomUseInfoB)
        {

            if (roomUseInfoA == null)
            {
                if (roomUseInfoB == null)
                {
                    // If x is null and y is null, they're
                    // equal. 
                    return 0;
                }
                else
                {
                    // If x is null and y is not null, y
                    // is greater. 
                    return -1;
                }
            }
            else
            {
                // If x is not null...
                //
                if (roomUseInfoB == null)
                // ...and y is null, x is greater.
                {
                    return 1;
                }
                else
                {
                    // ...and y is not null, compare the 
                    // lengths of the two strings.
                    //
                    int retval = roomUseInfoA.Key.Length.CompareTo(roomUseInfoB.Key.Length);

                    if (retval != 0)
                    {
                        // If the strings are not of equal length,
                        // the longer string is greater.
                        //
                        return retval;
                    }
                    else
                    {
                        // If the strings are of equal length,
                        // sort them with ordinary string comparison.
                        //
                        return roomUseInfoA.Key.CompareTo(roomUseInfoB.Key);
                    }
                }
            }

           
        
        }

        public static List<RoomUseInfo>  RoomFloorSumList
        {

            get
            {

                List<RoomUseInfo> list = new List<RoomUseInfo>();
                //DataTable dt = new DataTable();
                //DataColumn col1=new DataColumn("Key",typeof(string));
                //DataColumn col2 = new DataColumn("RoomSum", typeof(int));
                //DataColumn col3 = new DataColumn("InUse", typeof(int));
                //DataColumn col4 = new DataColumn("CanUse", typeof(int));
                //DataColumn col5 = new DataColumn("InUseRate", typeof(string));
                //dt.Columns.Add(col1);
                //dt.Columns.Add(col2);
                //dt.Columns.Add(col3);
                //dt.Columns.Add(col4);
                //dt.Columns.Add(col5);
                foreach (RoomUseInfo item in roomFloorSumDic.Values)
                {
                    //DataRow row= dt.NewRow();
                    //row["Key"] = item.Key;
                    //row["RoomSum"] = item.RoomSum;
                    //row["InUse"] = item.InUse;
                    //row["CanUse"] = item.CanUse;
                    //row["InUseRate"] = item.InUseRate;
                    //dt.Rows.Add(row); 


                    list.Add(item);

                }
                list.Sort(CompareByKey);
                //dt.or
                return list;

            }


        }

        public static void Clear()
        {
            roomTypeSumDic.Clear();
            roomTypeSumDic.Clear();
            roomFloorSumDic.Clear();
            
        
        }




       

    }
}
